package com.share.rule.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.share.rule.domain.FeeRule;
import com.share.rule.mapper.FeeRuleMapper;
import com.share.rule.service.IFeeRuleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class FeeRuleServiceImpl extends ServiceImpl<FeeRuleMapper, FeeRule> implements IFeeRuleService {


    /**
     * 查询费用规则列表
     */
    @Override
    public List<FeeRule> selectFeeRuleList(FeeRule feeRule) {
        // 规则名称
        String name = feeRule.getName();
        // 状态代码，1有效，2关闭
        String status = feeRule.getStatus();

        LambdaQueryWrapper<FeeRule> wrapper = new LambdaQueryWrapper<>();

        if (StrUtil.isNotEmpty(name)) {
            wrapper.like(FeeRule::getName, name);
        }

        if (StrUtil.isNotEmpty(status)) {
            wrapper.eq(FeeRule::getStatus, status);
        }

        wrapper.eq(FeeRule::getStatus, "0");

        return this.list(wrapper);
    }

    /**
     * 获取全部费用规则
     */
    @Override
    public List<FeeRule> getALLFeeRuleList() {
        return baseMapper.selectList(new LambdaQueryWrapper<FeeRule>().eq(FeeRule::getStatus, "1"));
    }
}
